#!/bin/bash

cd `dirname $0`
pwd

source /etc/profile

betaPath=$1
patchPath=$betaPath/patch
binPath=$betaPath/bin
etcPath=$betaPath/etc

chmod -R 777 $patchPath
chmod 777 jq-linux64

nameplate=$2

launchFile=$etcPath/launch.json
patchConfigFile=$patchPath/patchConfig.json
echo $launchFile
echo $patchConfigFile

group=`./jq-linux64 -r .group $launchFile`
exclusions=`./jq-linux64 -r .exclusions $patchConfigFile |  awk BEGIN{RS=EOF}'{gsub(/\n/,",");print}'`
echo $group
echo $exclude

#./stop.sh $group $exclude $nameplate > output.log 2>&1
#ret=$?

#if [ $ret != 0 ]; then
#  cat output.log >&2
#  echo $ret
#  exit $ret
#else
#  echo "$output"
#fi

##
java -jar patchinstaller-btcloud-1.0.jar $patchPath $etcPath > output.log 2>&1
ret=$?

if [ $ret != 0 ]; then
  cat output.log >&2
  echo $ret
  exit $ret
else
  echo "$output"
  echo $ret
fi


# call upgrade process
##

#./start.sh $group $exclude $nameplate > output.log 2>&1
#ret=$?

#if [ $ret != 0 ]; then
#  cat output.log >&2
#  echo $ret
#  exit $ret
#else
#  echo "$output"
#fi

